var keyGlobal = 0
// 记录所有navigatoritem
var NavigatorItemArray = []

class NavigatorItem {
  /**
   * @constructor
   * @param {String} label
   * @param {NavigatorItem[]} children
   */
  constructor(label, children = []) {
    this.label = label
    this.drop = false
    this.offset = 0
    this.children = children
    this.key = keyGlobal ++
    NavigatorItemArray[this.key] = this
  }

  /**
   * @param {NavigatorItem} child
   */
  addChild(child) {
    this.children.push(child)
  }
}

const goat_milk_type = [
  '纯羊奶粉',
  '配方羊奶粉',
  '陕西羊奶粉',
  '非陕西羊奶粉'
]
const shaanxi_goat_milk = [
  '宝鸡市',
  '渭南市',
  '西安市',
  '咸阳市'
]
const quota = [
  '色泽',
  '粒度、浊度',
  '氨基酸',
  '矿物质',
  '维生素'
]
function getQuotaNav() {
  var res = []
  quota.forEach((q) => {
    res.push(new NavigatorItem(q))
  })
  return res
}

var navigators = []

var a = new NavigatorItem('纯与配方羊奶粉标签值比较结果')
var b = new NavigatorItem('陕西与非陕西羊奶粉标签值比较结果')
var c = new NavigatorItem('对比结果', [a, b])
var d = []
shaanxi_goat_milk.forEach((pvc) => {
  d.push(new NavigatorItem(pvc))
})
var e = []
goat_milk_type.forEach((tp) => {
  if (tp == '陕西羊奶粉') {
    e.push(new NavigatorItem(tp, d))
  }
  else {
    e.push(new NavigatorItem(tp))
  }
})
var f = new NavigatorItem('营养标签结果', e)
navigators.push(new NavigatorItem('羊奶粉营养标签结果及比较', [f, c]))

var g = new NavigatorItem('对比结果', getQuotaNav())
var h = []
goat_milk_type.forEach((tp) => {
  if (tp == '陕西羊奶粉') {
    var res = []
    shaanxi_goat_milk.forEach((pvc) => {
      res.push(new NavigatorItem(pvc, getQuotaNav()))
    })
    h.push(new NavigatorItem('陕西羊奶粉', res))
  }
  else {
    h.push(new NavigatorItem(tp, getQuotaNav()))
  }
})
var i = new NavigatorItem('品质指标结果', h)
navigators.push(new NavigatorItem('羊奶粉品质指标结果及比较', [i, g]))

/**
 * @param {NavigatorItem} root
 * @param {Number} offset
 */
function setOffset(root, offset) {
  root.offset = offset
  root.children.forEach((child) => {
    setOffset(child, offset + 1)
  })
}
navigators.forEach((nav) => {
  setOffset(nav, 0)
})

// console.log(navigators)

module.exports = {
    navigators,
    NavigatorItemArray
}
